#pragma GCC optimize(2)
#include <iostream>
#include <math.h>
#include <map>
#include <vector>
using namespace std;
/*
    动态规划，上台阶问题，一次可以上1，2，3步，三种情况
    1. 先判断最基本的情况
    2. 然后写出状态转移方程dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]
    3. 更近一步，当前状态只与前三个有关，所以可以不用数组，而直接用变量存储即可，节省空间复杂度
*/
int dp(int m)
{
    if (m <= 2)
    {
        return m;
    }
    if (m == 3)
    {
        return 4;
    }
    if (m == 4)
    {
        return 7;
    }
    long long unsigned int f = 1, s = 2, t = 4, res = 7;
    for (int i = 5; i <= m; i++)
    {
        f = s;
        s = t;
        t = res;
        res = f + s + t;
    }
    return res;
}
void test()
{
    int n;
    vector<long long unsigned int> res;
    while (cin >> n, n != 0)
    {
        res.push_back(dp(n));
    }
    for (size_t i = 0; i < res.size(); i++)
    {
        cout << res[i] << endl;
    }
}

int main()
{
    test();
    return 0;
}